#!/usr/bin/env bash

if [ $(whoami) != 'mysql' ]; then
    echo 'This script must be run as the "mysql" user. Rerunning...'
    exec gosu mysql azuracast_db "$@"
fi

MYSQL_HOST="${MYSQL_HOST:-localhost}"
MYSQL_PORT="${MYSQL_PORT:-3306}"
MYSQL_USER="${MYSQL_USER:-azuracast}"
MYSQL_PASSWORD="${MYSQL_PASSWORD:-azur4c457}"
MYSQL_DATABASE="${MYSQL_DATABASE:-azuracast}"

exec mariadb --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} \
    --host=${MYSQL_HOST} --port=${MYSQL_PORT} --database=${MYSQL_DATABASE} "$@"
